package io.xxx.mario.job;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.quartz.SchedulerException;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/job")
public class JobController {

    @Resource
    private JobService jobService;

    @PostMapping("/add")
    public Long add(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) throws SchedulerException {
        return jobService.addJob(date);
    }

    @PostMapping("/interrupt")
    public boolean interruptJob(@RequestParam Long jobId) throws SchedulerException {
        return jobService.interruptJob(jobId);
    }
}
